#!/usr/bin/env.python
# _*_ coding:utf-8 _*_
# # # # # # # # # # # # # # # # # # # #
#  题目:      goods的序列化器           #
#  姓名:         李吉辉                #
#  时间:    2018年12月29日00:12:50     #
# # # # # # # # # # # # # # # # # # # #
from drf_haystack.serializers import HaystackSerializer
from rest_framework import serializers

from .search_indexes import SKUIndex
from .models import SKU



class SKUListSerializer(serializers.ModelSerializer):
    """sku序列化器"""

    # 元类
    class Meta:
        # 映射的模型
        model = SKU
        # 要映射的字段
        fields = ('id', 'name', 'price', 'default_image_url', 'comments')



#  全文检索 第七步: 创建搜索序列化器
class SKUSearchSerializer(HaystackSerializer):
    """
    SKU索引结果数据序列化器
    """
    object = SKUListSerializer(read_only=True)

    class Meta:
        index_classes = [SKUIndex]
        fields = ('text', 'object')